package boardgamer.yavalath.client.pro;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import boardgamer.licensing.Licensing;
import boardgamer.yavalath.client.LiteProFeatures;
import boardgamer.yavalath.client.SharedObjects;
import boardgamer.yavalath.client.YavalathActivity;

/**
 * @author garysoed
 */
public class YavalathProActivity extends Activity {

  private static final byte[] SALT = {
    -66,  14, -29, -99,
    126,  23,   3,   8,
     51, 109,  46, -86,
     73, -87, -24,  35,
    102, 103, -81, 111 };
  
  private static final String PUBLIC_KEY
      = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiOTGCdr9E5/z38cEx+5LQJvxTE4mtHnKqT4FII3kKfHSF+"
          + "zmzAayeE4Q1eUBxnDIBkZ+a0hWWwK0pcVIvB23hf/zddNLIiJ/vJO6lnzpEvOINihKvMp9cXZtRNX+Dw7SLi99"
          + "Kz04BrlhYx93tddW7VKn3FIUs+cvAK42FVudH++A8v3dHR7S2jFO7p0wIo15LlJmuskmeqrh3/kXIam2/Ck6+R"
          + "/JoqbU1yR51dvx2M6jrwua7ky77YyF1S5494j2Rk26OObucd1b5e64+ucU0pWaJ49wWRepsHa3W2U2b37L7D50"
          + "XTG2cUG+gh9qx4bNPUbs2LJu1B/j8yreeGNoLQIDAQAB";

  private Licensing licensing;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ProImageHandler.initialize(this);
    ProStringHandler.initialize(this);

    this.licensing = new Licensing(this, SALT, PUBLIC_KEY, new Licensing.CheckCallback() {
      @Override
      public void onAllowed() {
        SharedObjects.initialize(
            new ProFontHandler(YavalathProActivity.this),
            new ProProFeatures());
        startActivity(new Intent(YavalathProActivity.this, YavalathActivity.class));
      }

      @Override
      public void onDisallowed() {
        SharedObjects.initialize(
            new ProFontHandler(YavalathProActivity.this),
            new LiteProFeatures());
        Toast.makeText(
            YavalathProActivity.this,
            getResources().getText(R.string.error_no_license), Toast.LENGTH_LONG)
            .show();
        startActivity(new Intent(YavalathProActivity.this, YavalathActivity.class));
      }
    });
    licensing.startCheck();
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    licensing.destroy();
  }
}
